﻿package  
{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFieldAutoSize;
	import com.bit101.components.Label;
	import graph.Node;

	/**
	 * ...
	 * @author s
	 */
	public class NodeAttachedLabel extends TextField
	{
		private var _attachedGraphNode:Node;
		private const TEXT_FORMAT_SMALL:TextFormat = new TextFormat("", 12);
		private const TEXT_FORMAT_NORMAL:TextFormat = new TextFormat("", 16);
		private const TEXT_FORMAT_LARGE:TextFormat = new TextFormat("", 24);

		public function NodeAttachedLabel(parent:Sprite, x:Number, y:Number, text:String, weight:Number) 
		{
			super();
			super.text = text;
			super.autoSize = TextFieldAutoSize.LEFT;
			super.selectable = false;
			parent.addChild(this);

			_attachedGraphNode = new Node(text, weight);

			setPosition(x, y);
			setWeight(weight);
		}
		
		public function setPosition(x:Number, y:Number):void 
		{
			super.x = x - super.textWidth / 2;
			super.y = y - super.textHeight / 2;
		}
		
		public function setWeight(weight:Number):void 
		{
			if (_attachedGraphNode.weight == 1) {
				super.setTextFormat(TEXT_FORMAT_SMALL);
			}
			else if (_attachedGraphNode.weight < 5) {
				super.setTextFormat(TEXT_FORMAT_NORMAL);
			}
			else {
				super.setTextFormat(TEXT_FORMAT_LARGE);
			}
		}
		
		public function get attachedGraphNode():Node
		{
			return _attachedGraphNode;
		}
	}

}